Differential binding of the three PURA HeLa iCLIPs - 3 flag vs endo

Author

Melina Klostermann

Published

November 3, 2023

Show code
install.packages("ggplot2")
install.packages("ggpubr")
install.packages("ggrastr")
install.packages("ggpointdensity")
install.packages("viridis")

BiocManager::install("BindingSiteFinder")
BiocManager::install("GenomicFeatures")
BiocManager::install("DESeq2")
Show code
library(BindingSiteFinder)
library(dplyr)
library(GenomicFeatures)

1 Input

Show code
# path for output
outpath <- "~/Thesis/Thesis_code/PURA/07_Differential_binding/"

bds <- readRDS(paste0(outpath, "bds_merge_endo_flag.rds"))

bds
Dataset:  endo_flag
Object of class BSFDataSet 
#N Ranges:  147,893 
Width ranges:  5 
#N Samples:  6 
#N Conditions:  2 
Show code
# gene annotation
annotation <- readRDS("~/PURA/Molitor-et-al-2022/annotation.rds")
anno_txdb <- makeTxDbFromGRanges(annotation)

gns = genes(anno_txdb)
gns$gene_id = sub("\\..*", "", gns$gene_id)
idx = match(gns$gene_id, annotation$gene_id)
elementMetadata(gns) = cbind(elementMetadata(gns), elementMetadata(annotation)[idx,])
names(gns) = sub("\\..*", "", names(gns))
meta = data.frame(gene_id = gns$gene_id, gene_name = gns$gene_name, gene_type = gns$gene_type)
mcols(gns) = meta
gns$geneID = names(gns)

cdseq = cds(anno_txdb)
intrns = unlist(intronsByTranscript(anno_txdb))
utrs3 = unlist(threeUTRsByTranscript(anno_txdb))
utrs5 = unlist(fiveUTRsByTranscript(anno_txdb))
trl = GRangesList(CDS = cdseq, Intron = intrns, UTR3 = utrs3, UTR5 = utrs5)

# saveRDS(trl, paste0(outpath, "transcript_region_list_test.rds"))

2 Assign genes and regions

Show code
bds <- assignToGenes(bds, anno.genes = gns, overlaps = "frequency")

# saveRDS(bds, paste0(outpath, "bds_test.rds"))
#bds <- assignToTranscriptRegions(bds, anno.transcriptRegionList = trl, overlaps.rule = c("UTR3", "UTR5", "CDS", "Intron"))

# bds <- assignToTranscriptRegions(bds, anno.transcriptRegionList = trl, overlaps = "frequency")
# getRanges(bds)

3 Calculate background

Show code
# compute the binding site and background coverage
bds = calculateBsBackground(bds, anno.genes = gns)

# filter background 
bds = filterBsBackground(bds,
                          minCounts.cutoff = 1000,
                         balanceBackground.cutoff.bs = 0.2,
                         balanceBackground.cutoff.bg = 0.8)

plotBsBackgroundFilter(bds, filter = "minCounts")

Show code
plotBsBackgroundFilter(bds, filter = "balanceBackground")

Show code
plotBsBackgroundFilter(bds, filter = "balanceCondition")

4 Caluclate Changes

Show code
bds <- calculateBsFoldChange(bds)

5 Changes

5.1 background changes

Show code
plotBsMA(bds, what = "bg")

Show code
plotBsVolcano(bds, what = "bg")

5.2 binding changes

Show code
plotBsMA(bds, what = "bs")

Show code
plotBsVolcano(bds, what = "bs")

Show code
bs <- getRanges(bds) |> as.data.frame()

Number of binding sites: 146205

Number of sig changing binding sites: 46020

Number of sig changing background: 87732

5.3 binding vs background changes

Show code
bs <- bs |> mutate(bs, bin = cut(bg.log2FoldChange, breaks = seq(-3,3, 0.5)))

ggplot(bs, aes(x = bin, y = bs.log2FoldChange))+
  geom_violin()+
  geom_boxplot(width = 0.25)

6 Save file

Show code
# rds
saveRDS(bs, paste0(outpath, "merged_bs_diff_endo_flag_res.rds"))

# beds
up_bs <- bs |> subset((bs$bs.padj < 0.01) & (bs$bs.log2FoldChange > 0)) |>
  makeGRangesFromDataFrame()

down_bs <- bs |> subset((bs$bs.padj < 0.01) & (bs$bs.log2FoldChange < 0)) |>
  makeGRangesFromDataFrame()

up_bg <- bs |> subset((bs$bg.padj < 0.01) & (bs$bg.log2FoldChange > 0)) |>
  makeGRangesFromDataFrame()

down_bg <- bs |> subset((bs$bg.padj < 0.01) & (bs$bg.log2FoldChange < 0)) |>
  makeGRangesFromDataFrame()

rtracklayer::export.bed(up_bs, paste0("merged_bs_upbs_endovsflag.bed"))
rtracklayer::export.bed(down_bs, paste0("merged_bs_downbs_endovsflag.bed"))
rtracklayer::export.bed(up_bg, paste0("merged_bs_upbg_endovsflag.bed"))
rtracklayer::export.bed(down_bg, paste0("merged_bs_downbg_endovsflag.bed"))

7 Session info

Show code
sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Etc/UTC
tzcode source: system (glibc)

attached base packages:
[1] stats4    stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
 [1] DESeq2_1.41.12              SummarizedExperiment_1.31.1
 [3] GenomicFeatures_1.53.3      AnnotationDbi_1.63.2       
 [5] Biobase_2.61.0              dplyr_1.1.3                
 [7] BindingSiteFinder_1.99.14   GenomicRanges_1.53.3       
 [9] GenomeInfoDb_1.37.7         IRanges_2.35.3             
[11] S4Vectors_0.39.3            BiocGenerics_0.47.1        
[13] ggplot2_3.4.4               knitr_1.44                 

loaded via a namespace (and not attached):
  [1] RColorBrewer_1.1-3       rstudioapi_0.15.0        jsonlite_1.8.7          
  [4] shape_1.4.6              magrittr_2.0.3           ggbeeswarm_0.7.2        
  [7] farver_2.1.1             rmarkdown_2.25           GlobalOptions_0.1.2     
 [10] BiocIO_1.11.0            zlibbioc_1.47.0          vctrs_0.6.4             
 [13] Cairo_1.6-1              memoise_2.0.1            Rsamtools_2.17.0        
 [16] RCurl_1.98-1.12          ggpointdensity_0.1.0     rstatix_0.7.2           
 [19] webshot_0.5.5            htmltools_0.5.6.1        S4Arrays_1.1.6          
 [22] progress_1.2.2           distributional_0.3.2     curl_5.1.0              
 [25] broom_1.0.5              SparseArray_1.1.12       htmlwidgets_1.6.2       
 [28] plyr_1.8.9               cachem_1.0.8             GenomicAlignments_1.37.0
 [31] lifecycle_1.0.3          iterators_1.0.14         pkgconfig_2.0.3         
 [34] Matrix_1.6-1.1           R6_2.5.1                 fastmap_1.1.1           
 [37] GenomeInfoDbData_1.2.11  MatrixGenerics_1.13.2    clue_0.3-65             
 [40] digest_0.6.33            colorspace_2.1-0         RSQLite_2.3.1           
 [43] ggpubr_0.6.0             labeling_0.4.3           filelock_1.0.2          
 [46] fansi_1.0.5              httr_1.4.7               polyclip_1.10-6         
 [49] abind_1.4-5              compiler_4.3.1           bit64_4.0.5             
 [52] withr_2.5.1              doParallel_1.0.17        backports_1.4.1         
 [55] BiocParallel_1.35.4      viridis_0.6.4            carData_3.0-5           
 [58] DBI_1.1.3                ggforce_0.4.1            ggsignif_0.6.4          
 [61] biomaRt_2.57.1           MASS_7.3-60              rappdirs_0.3.3          
 [64] DelayedArray_0.27.10     rjson_0.2.21             tools_4.3.1             
 [67] vipor_0.4.5              beeswarm_0.4.0           glue_1.6.2              
 [70] restfulr_0.0.15          grid_4.3.1               cluster_2.1.4           
 [73] generics_0.1.3           gtable_0.3.4             tidyr_1.3.0             
 [76] hms_1.1.3                xml2_1.3.5               car_3.1-2               
 [79] utf8_1.2.4               XVector_0.41.2           foreach_1.5.2           
 [82] pillar_1.9.0             ggdist_3.3.0             stringr_1.5.0           
 [85] circlize_0.4.15          tweenr_2.0.2             BiocFileCache_2.9.1     
 [88] lattice_0.21-8           rtracklayer_1.61.2       bit_4.0.5               
 [91] tidyselect_1.2.0         locfit_1.5-9.8           ComplexHeatmap_2.17.0   
 [94] Biostrings_2.69.2        gridExtra_2.3            svglite_2.1.2           
 [97] xfun_0.40                matrixStats_1.0.0        stringi_1.7.12          
[100] yaml_2.3.7               kableExtra_1.3.4         evaluate_0.22           
[103] codetools_0.2-19         tibble_3.2.1             cli_3.6.1               
[106] systemfonts_1.0.5        munsell_0.5.0            Rcpp_1.0.11             
[109] dbplyr_2.3.4             png_0.1-8                ggrastr_1.0.2           
[112] XML_3.99-0.14            parallel_4.3.1           blob_1.2.4              
[115] prettyunits_1.2.0        bitops_1.0-7             viridisLite_0.4.2       
[118] scales_1.2.1             purrr_1.0.2              crayon_1.5.2            
[121] GetoptLong_1.0.5         rlang_1.1.1              KEGGREST_1.41.4         
[124] rvest_1.0.3